home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NETWORK.SWG / 0015_Novell User Name 3.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  3KB  |  114 lines

  1. {
  2. >I need a way to get the current user name from the netware shell.
  3. >For instance, if I'm logged into server MYSERVER as user SUPERVISOR,
  4. >I need some way to get 'supervisor' as the user name.  (Kind of like
  5. >WHOAMI would return: You are user SUPERVISOR on server MYSERVER)
  6.  
  7. In our library of routines we've developed (and continue to do so) lots of
  8. routines for Novell Netware.  The following routines (developed by Peter Ogden
  9. is to and myself) are to get the current user and I hope I've removed all our
  10. inter-library references so that it's of use to you:
  11. }
  12.  
  13. type
  14.   String48 = string [48];
  15.  
  16. const
  17.   NetError : Integer = 0;
  18.  
  19. function GetConnNo : Byte; assembler;
  20.  
  21. asm
  22.         MOV  AX, $DC00
  23.         INT  $21
  24. end;
  25.  
  26. procedure GetConnInfo (ConnectionNum : Byte; var ObjType : Word;
  27.                             var ObjName : String48);
  28.  
  29. var
  30.   ReqBuf :     record
  31.                       Size       : Word;
  32.                       FixedValue : Byte;
  33.                       ConnNumber : Byte;
  34.                  end;
  35.  
  36.   ReplyBuf :     record
  37.                       Size       : Word;
  38.                       ID         : LongInt;
  39.                       ObType     : Word;
  40.                       Name       : array [1..48] of Byte;
  41.                       Reserved   : Byte;
  42.                       LoginTime  : array [1..7] of Byte;
  43.                  end;
  44.  
  45.   Regs        : Registers;
  46.   Counter     : Integer;
  47.   NameString  : String;
  48.  
  49. begin
  50.   with ReqBuf do
  51.   begin
  52.        Size := SizeOf (ReqBuf) - 2;
  53.        FixedValue := $16;
  54.        ConnNumber := ConnectionNum;
  55.   end;
  56.  
  57.   ReplyBuf.Size := SizeOf (ReplyBuf) - 2;
  58.   with Regs do
  59.   begin
  60.        AH := $E3;
  61.        DS := Seg (ReqBuf);
  62.        SI := Ofs (ReqBuf);
  63.        ES := Seg (ReplyBuf);
  64.        DI := Ofs (ReplyBuf);
  65.        MsDos (Regs);
  66.  
  67.        NetError := AL;
  68.        if NetError <> 0 then
  69.        begin
  70.             ObjType := 0;
  71.             ObjName := '';
  72.        end
  73.        else
  74.             with ReplyBuf do
  75.             if ID <> 0 then
  76.             begin
  77.                  Counter := 1;
  78.                  NameString := '';
  79.                  while (Name[Counter] <> 0) do
  80.                  begin
  81.                       NameString := NameString + Chr (Name [Counter]);
  82.                       Inc (Counter);
  83.                  end;
  84.                  ObjName := NameString;
  85.                  ObjType := Swap (ObType);
  86.             end
  87.             else
  88.             begin
  89.                  ObType := 0;
  90.                  ObjName := '';
  91.             end;
  92.   end;
  93. end;
  94.  
  95. function GetUserID : String48;
  96.  
  97. var
  98.   CN : Byte;
  99.   UserName : String48;
  100.   ObjType : Word;
  101.  
  102. begin
  103.   CN := GetConnNo;
  104.   GetConnInfo (CN, ObjType, UserName);
  105.   GetUserID := UserName;
  106. end;
  107.  
  108.  
  109. I use this with Novell Netware 386 v3.11, as that is the Network that most of
  110. our Commercial Applications have been developed for.  I know speed ups are
  111. possible especially in processing the ASCIIZ, but hey we only call this routine
  112. once in an application so it's not high on our priorities for optimisation.
  113.  
  114.